const setItem = (key, data, expireAt) => {   // new Date('2021-11-8')
  const expireData = JSON.stringify({
    data,
    expireAt
  })
  localStorage.setItem(key, expireData)
}

const getItem = (key) => {
  let expireData = localStorage.getItem(key)
  if (!expireData) return null
  expireData = JSON.parse(expireData)
  const {data, expireAt} = expireData
  if (expireAt  && new Date().getTime() > expireAt.getTime()) {
    localStorage.removeItem(key)
    return null
  } else {
    return data
  }
}



export  {
  setItem,
  getItem
}

